import scrapy
import json
from douyu.items import DouyuItem

class DouyuspiderSpider(scrapy.Spider):
    name = 'douyuspider'
    allowed_domains = ['douyucdn.cn']
    page = 0
    url = 'http://capi.douyucdn.cn/api/v1/getVerticalRoom?limit=20&offset='
    start_urls = [url + str(page)]

    def parse(self, response):
        data_jsons = json.loads(response.text)['data']
        for data_json in data_jsons:
            nickname = data_json['nickname']
            vertical_src = data_json['vertical_src']

            # 实例化一个对象
            item = DouyuItem()
            item['name'] = nickname
            item['image_urls'] = vertical_src
            # 提交对象到管道
            yield item

            # yield DouyuItem(nickname=nickname, image_urls=vertical_src)

        # self.page += 20
        # yield scrapy.Request(self.url + str(self.page), callback=self.parse)



